package com.zhang.boot.web.controller;

import com.zhang.boot.core.annotation.Decrypt;
import com.zhang.boot.core.service.LoginService;
import com.zhang.boot.core.vo.LoginUser;
import com.zhang.boot.core.vo.Result;
import com.zhang.boot.core.vo.login.LoginRequest;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

@RestController
@RequiredArgsConstructor
@Api(tags = "登录接口")
public class LoginController {

    private final LoginService loginService;

    @GetMapping("/captchaImage")
    @ApiOperation("获取验证码")
    public Result captchaImage() {
        Result result = loginService.captchaImage();
        return result;
    }

    /**
     * 登录请求
     *
     * @param request
     * @return
     */
    @PostMapping("/login")
    @ApiOperation("登录")
    @Decrypt
    public Result login(@Valid @RequestBody LoginRequest request) {
        LoginUser loginUser = loginService.login(request);
        return Result.ok(loginUser);
    }

}
